<?php $this->load->view('inc/top.php');?>
<style>
#cart{ color:#F30;overflow:hidden;float:right;width:150px; border:solid 5px #3CF; background:#FF3;margin-top:15px;} 
#products {background:#39C; width:100%; color:#FFF; margin-bottom:10px;font-weight:bold;}
#products b {color:#FF0;}
#products a {font-size:18px;float:right;color:#F90;}
#container {overflow:hidden; margin-top:100px;}
</style>
<script type="text/javascript">
<!--
	$(document).ready(function(){
		getData(0);
		//addToCart("#empty");
		});
	function getData(page){
	$.ajax({
			type : 'GET',
			url  : 'paging',
			data : 'page='+page,
			success : function(msg){
					var pagination = "";
					var table = "";
					//alert(msg);
					var getData = jQuery.parseJSON(msg);
					var recordNums = getData.record_num;
					var pageNums = getData.page_num;
					var startLoop = getData.start_loop;
					var endLoop = getData.end_loop;
					var data = getData.database;
	
					$(data).each(function(index, value){
							table += "<table id='products' border='1'>";
							table += "<tr><td><b>Mã sản phẩm : </b>"+value.id+"<br><b>Tên sản phẩm</b>"+value.name+"<br><b>Giá</b>"+value.price+"<br>";
							table += "<a href='#' v='"+value.id+"' onclick='addToCart(this);'>Mua</a>";
							table += "</td></tr></table>";
							table += "<br />";
						});
					
					pagination += "<input type='button' value ='Đầu' onclick='getData(0);'>";
					for(var i=startLoop; i<=endLoop;i++){
							pagination += "<input type='button' value ='"+i+"' onclick='getData(this.value);'>";
						}
					pagination += "<input type='button' value ='Cuối' onclick='getData("+pageNums+");'>";
					$('#container').html(table);
					$('#pagination').html(pagination);
				}
		});
	}
	function addToCart(id){ 
		jQuery.ajax({
				url : 'addToCard',
				type : 'GET',
				data : 'id='+jQuery(id).attr('v'),
				success : function(string){
				var data = "";
				jQuery('#number').html(string+" ");
				}
			});
	}

//-->
</script>
  <div id="templatemo_content">
  	<div id="templatemo_content_left">
  	<div id='cart'>
    Bạn có tổng cộng <b id="number"><?php echo $cart_num;?> </b>món
    trong giỏ hàng của bạn
    <a href="cart" title="cart detail" > Xem giỏ hàng </a>
    </div>
    <input type = "hidden" id="empty" v="empty">
    <div id="container"></div>
	<div id="pagination"></div>

  	</div> 
  <?php $this->load->view('inc/right.php');?>
<?php $this->load->view('inc/bottom.php');?>